from PyQt4.QtGui import QWidget,QTreeView,QStandardItemModel,QStandardItem,QBrush,QColor,QFont,QSortFilterProxyModel,QItemSelection,QItemSelectionModel,QSizePolicy
from PyQt4 import QtCore
from PyQt4.QtCore import QString,Qt,QVariant,QStringList
import xml.etree.ElementTree as ET
import sys,importlib
from KCharts.ui_KIndicatorTreeWidget import Ui_KIndicatorTreeWidget
import cPickle as pickle
class KIndicatorTreeWidget(QWidget):
	''' The UI of strategy batch test '''
	IndicatorChanged=QtCore.pyqtSignal(dict) # tell other indicator selection is updated
	def __init__(self, parent=None):
		super(KIndicatorTreeWidget, self).__init__(parent)
		self.ui =  Ui_KIndicatorTreeWidget()
		self.ui.setupUi(self) 
		
		self.mLayout=self.layout()
		self.mLayout.setContentsMargins(0,0,0,0) # set blank space between outside of layout and its parent widget		
		self.mLayout.setSpacing(0)
		
		# set size policy
		sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)
		sizePolicy.setHorizontalStretch(1)
		sizePolicy.setVerticalStretch(0)
		self.setSizePolicy(sizePolicy)
		self.setMinimumWidth(100)
		
		# forward methods to view
		themodel=self.ui.IndicatorTreeView.model()
		for m in [ 'ReSendAllCheckedItem']: 
			setattr(self, m, getattr(self.ui.IndicatorTreeView, m))
		
		# forward methods to model
		themodel=self.ui.IndicatorTreeView.model()
		for m in [ 'OnSave', 'OnClear','GetAllCheckedItems']: 
			setattr(self, m, getattr(themodel, m))	
			
		# set up signal
		self.ui.SaveBtn.clicked.connect(themodel.OnSave)
		self.ui.ClearBtn.clicked.connect(themodel.OnClear)
		self.ui.IndicatorTreeView.IndicatorChanged.connect(self.IndicatorChanged)
		





